/**
 * 
 */
package ga.nqueens;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.jheuristics.DefaultIndividual;
import org.jheuristics.Individual;
import org.jheuristics.ga.GAConfig;
import org.jheuristics.ga.IndividualsFactory;

/**
 * @author thiago
 *
 */
public class NQueensIndividualFactory implements IndividualsFactory {

	private final int boardDimension;
	
	/**
	 * @param boardDimension
	 */
	public NQueensIndividualFactory(final int boardDimension) {
		this.boardDimension = boardDimension;
	}

	/* (non-Javadoc)
	 * @see org.jheuristics.ga.IndividualsFactory#createRandomIndividual(org.jheuristics.ga.GAConfig)
	 */
	public Individual createRandomIndividual(GAConfig config) {
		
		List<Integer> gens = new ArrayList<Integer>(boardDimension);

		for (int i = 0; i < boardDimension; i++) {
			gens.add(0, i);
		}
		
		Collections.shuffle(gens);
		
		return createSpecificIndividual(gens, config);
	}

	/* (non-Javadoc)
	 * @see org.jheuristics.ga.IndividualsFactory#createSpecificIndividual(java.lang.Object, org.jheuristics.ga.GAConfig)
	 */
	public Individual createSpecificIndividual(Object gens, GAConfig config) {
		return new DefaultIndividual(gens);
	}

}